package com.jd.controller;

import com.jd.entity.School;
import com.jd.service.SchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController

@RequestMapping("school")
public class SchoolController {
    @Autowired
    private SchoolService schoolService;
@GetMapping
    public List<School> getAllSchools() {
        return schoolService.getAllSchools();
    }
@GetMapping(params = "schoolName")
    public List<School> getSchoolByName(String schoolName) {

        return schoolService.getSchoolByName(schoolName);
    }
@GetMapping("{id}")
    public School getSchoolById(@PathVariable int id) {
        return schoolService.getSchoolById(id);
    }
@DeleteMapping("{id}")
    public int deleteSchoolById(@PathVariable int id) {
        return schoolService.deleteSchoolById(id);
    }
@PostMapping
    public int insertSchool(@RequestBody School school) {
        return schoolService.insertSchool(school);
    }

@PutMapping
    public int updateSchool(@RequestBody School school) {
        return schoolService.updateSchool(school);
    }
}
